package com.zoweunion.mechanic.controller;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zoweunion.mechanic.controller.BaseController;
import com.zoweunion.mechanic.util.constants.Constants;
import com.zoweunion.mechanic.util.MyException;
import com.zoweunion.mechanic.service.GarbageLocationService;
import com.zoweunion.mechanic.entity.GarbageLocationEntity;


import com.zoweunion.mechanic.model.ResponseBean;
import com.github.pagehelper.PageInfo;
import javax.servlet.http.HttpServletRequest;



/**
 * 垃圾点经纬度
 *
 * @author xp
 * @email 17688825585@163.com
 * @date 2020-09-15 14:14:06
 */
@RestController
@RequestMapping("/garbagelocation")
public class GarbageLocationController extends BaseController {
    @Autowired
    private GarbageLocationService garbageLocationService;

    /**
     * 列表
     */
    @GetMapping("/garbageLocationList")
    public ResponseBean garbageLocationList(@RequestParam Map<String, Object> params, HttpServletRequest request)  throws MyException{
        params.put("s_id", getCurrentUser(request).getS_id());
        params.put("user_id", getCurrentUser(request).getId());
        List<GarbageLocationEntity> info= garbageLocationService.queryPage(params);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", info);
    }

    /**
     * 新增
     */
    @PostMapping("/garbageLocationInsertUpdate")
    public ResponseBean garbageLocationInsertUpdate(@RequestBody GarbageLocationEntity params,
                                             HttpServletRequest request) {
        if (params.getId()!=null){
                garbageLocationService.updateById(params);
        }else {
                garbageLocationService.save(params);
        }
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }

    /**
     * 删除 假删
     */
    @PostMapping("/deleteLocation")
    public ResponseBean deleteLocation(@RequestBody GarbageLocationEntity params,
                                                    HttpServletRequest request) {
        params.setDeleteFlag(1);
        garbageLocationService.updateById(params);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }


}
